/*
 *@# Agency Created on 2004-7-28
 *
 *
 * Copyright: Bluejay Networks Inc. & Inquiry Management Systems Ltd.  2004
 *
 * This software is the proprietary information of Bluejay Networks Inc. & 
 * Inquiry Management Systems Ltd.  
 * Use is subject to license terms.
 */
package com.ims.iaa.AD;

import java.io.Serializable;
import java.net.URL;
/**
 * This class is use to save a agency information(now, only save
 * AgencyID and Keywords), it be used to judge whether the advertisement
 * URL is refering to this agency.
 *  
 * @author ShengMeng Bai
 * @version 1.0
 */
public class AdAgency implements Serializable, Cloneable {
	/**
	 * The agency ID which save in database
	 */
	private int m_iAgencyID;
	/**
	 * The keywords is use to identify
	 * whether the URL is refering to this agency.
	 * @see IsRefering
	 */
	private String[] m_arrayKeywords;
	
	/**
	 * @param iAgencyID the AgencyID which is saved in the database
	 * @param sKeyWords the agency keywords, if keyword is more than on,
	 * split them with semicolon.
	 */
	public AdAgency( int iAgencyID, String sKeyWords ){
		m_iAgencyID = iAgencyID;
		if (sKeyWords != null){
			m_arrayKeywords = sKeyWords.split(";");
		}
	}
	
	public int getAgencyID(){
		return m_iAgencyID;
	}
	/**
	 * Identify whether the URL is refering to this agency,
	 * if the URL can match a keywords, system will regard as
	 * the advertisement is refering to the agency.
	 * 
	 * @param urlTargetHost the host URL of advertisement target
	 * @return if URL refering to this agency return true,
	 * otherwise return false. 
	 */
	public boolean IsRefering( final URL urlTargetHost ){
		if (m_arrayKeywords == null)
		{
			return false;
		}
		int iLen = m_arrayKeywords.length;
		String sURL = urlTargetHost.toString();
		for(int iIndex = 0; iIndex < iLen; iIndex++){
			if (sURL.indexOf(m_arrayKeywords[iIndex]) != -1){
				return true;
			}
		}
		return false;
	}
}
